package ge.telasi.tasks.ui;

import ge.telasi.tasks.LocaleManager;
import ge.telasi.tasks.model.User;
import ge.telasi.tasks.ui.appconfig.AppConfigView;
import ge.telasi.tasks.ui.flowpermission.FlowPermissionAdminView;
import ge.telasi.tasks.ui.flowpermission.FlowPermissionView;
import ge.telasi.tasks.ui.log.LoggerUtils;
import ge.telasi.tasks.ui.reporting.TaskCompReportFrame;
import ge.telasi.tasks.ui.structure.StructureView;
import ge.telasi.tasks.ui.task.NewTaskDialog;
import ge.telasi.tasks.ui.task.TaskView;
import ge.telasi.tasks.ui.user.ChangePasswordDialog;
import ge.telasi.tasks.ui.user.GroupAdminView;
import ge.telasi.tasks.ui.user.GroupView;
import ge.telasi.tasks.ui.user.LoginDialog;
import ge.telasi.tasks.ui.user.ServerItemSelectorDialog;
import ge.telasi.tasks.ui.user.UserPropertiesDialog;
import ge.telasi.tasks.ui.user.UserRegistrationDialog;
import ge.telasi.tasks.ui.user.UserAdminView;
import ge.telasi.tasks.ui.user.UserView;
import java.awt.Desktop;
import java.net.URI;
import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

/**
 * @author dimitri
 */
public class MainFrame extends javax.swing.JFrame {
    private static final long serialVersionUID = 5164151749245255773L;
    private TaskView taskFrame;

    boolean isTaskFrameVisible() {
        return taskFrame != null && taskFrame.isVisible();
    }

    void openTaskFrame() {
        miTasksActionPerformed(null);
    }

    void refreshTaskList() {
        if (taskFrame != null) {
            taskFrame.refresh();
        }
    }

    public MainFrame() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnMain = new javax.swing.JMenu();
        miLogin = new javax.swing.JMenuItem();
        miLogout = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        miMyAccount = new javax.swing.JMenuItem();
        miCnangePassword = new javax.swing.JMenuItem();
        miRegistration = new javax.swing.JMenuItem();
        jSeparator0 = new javax.swing.JSeparator();
        miExit = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        miTasks = new javax.swing.JMenuItem();
        miNewTask = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        miFlowPermissionView = new javax.swing.JMenuItem();
        miUserView = new javax.swing.JMenuItem();
        miUserGroupView = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        miTaskCompilationReport = new javax.swing.JMenuItem();
        mnWebPage = new javax.swing.JMenu();
        miHomePage = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        miAbout = new javax.swing.JMenuItem();
        mnAdmin = new javax.swing.JMenu();
        miAppConfig = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        miStructure = new javax.swing.JMenuItem();
        miUserEdit = new javax.swing.JMenuItem();
        miUserGroups = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        miFlowPermission = new javax.swing.JMenuItem();

        setTitle("დაავალე! სს თელასის დავალებათა მართვის სისტემა");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        mnMain.setText("ძირითადი");

        miLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/connect.png"))); // NOI18N
        miLogin.setText("მოხმარებლის შესვლა");
        miLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLoginActionPerformed(evt);
            }
        });
        mnMain.add(miLogin);

        miLogout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/disconnect.png"))); // NOI18N
        miLogout.setText("მომხმარებლის გასვლა");
        miLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLogoutActionPerformed(evt);
            }
        });
        mnMain.add(miLogout);
        mnMain.add(jSeparator2);

        miMyAccount.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/user.png"))); // NOI18N
        miMyAccount.setText("ჩემი ანგარიში");
        miMyAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMyAccountActionPerformed(evt);
            }
        });
        mnMain.add(miMyAccount);

        miCnangePassword.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/lock_edit.png"))); // NOI18N
        miCnangePassword.setText("პაროლის შეცვლა");
        miCnangePassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCnangePasswordActionPerformed(evt);
            }
        });
        mnMain.add(miCnangePassword);

        miRegistration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/user_add.png"))); // NOI18N
        miRegistration.setText("ახალი მომხმარებლის რეგისტრაცია");
        miRegistration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miRegistrationActionPerformed(evt);
            }
        });
        mnMain.add(miRegistration);
        mnMain.add(jSeparator0);

        miExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/cross.png"))); // NOI18N
        miExit.setText("გასვლა");
        miExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExitActionPerformed(evt);
            }
        });
        mnMain.add(miExit);

        jMenuBar1.add(mnMain);

        jMenu1.setText("დავალება");

        miTasks.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/email.png"))); // NOI18N
        miTasks.setText("დავალებების მართვა");
        miTasks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miTasksActionPerformed(evt);
            }
        });
        jMenu1.add(miTasks);

        miNewTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/add.png"))); // NOI18N
        miNewTask.setText("ახალი დავალება");
        miNewTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miNewTaskActionPerformed(evt);
            }
        });
        jMenu1.add(miNewTask);
        jMenu1.add(jSeparator3);

        miFlowPermissionView.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/email_go.png"))); // NOI18N
        miFlowPermissionView.setText("მიმოსვლის წესები");
        miFlowPermissionView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miFlowPermissionViewActionPerformed(evt);
            }
        });
        jMenu1.add(miFlowPermissionView);

        miUserView.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/user.png"))); // NOI18N
        miUserView.setText("მომხმარებელთა სია");
        miUserView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miUserViewActionPerformed(evt);
            }
        });
        jMenu1.add(miUserView);

        miUserGroupView.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/group.png"))); // NOI18N
        miUserGroupView.setText("მომხმარებელთა ჯგუფები");
        miUserGroupView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miUserGroupViewActionPerformed(evt);
            }
        });
        jMenu1.add(miUserGroupView);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("რეპორტები");

        miTaskCompilationReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/accept.png"))); // NOI18N
        miTaskCompilationReport.setText("დავალებათა შესრულება");
        miTaskCompilationReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miTaskCompilationReportActionPerformed(evt);
            }
        });
        jMenu2.add(miTaskCompilationReport);

        jMenuBar1.add(jMenu2);

        mnWebPage.setText("დახმარება");

        miHomePage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/world.png"))); // NOI18N
        miHomePage.setText("დავალებათა სისტემის ვიკი");
        miHomePage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miHomePageActionPerformed(evt);
            }
        });
        mnWebPage.add(miHomePage);
        mnWebPage.add(jSeparator5);

        miAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/note.png"))); // NOI18N
        miAbout.setText("პროგამის შესახებ");
        miAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAboutActionPerformed(evt);
            }
        });
        mnWebPage.add(miAbout);

        jMenuBar1.add(mnWebPage);

        mnAdmin.setText("ადმინისტრირება");

        miAppConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/wrench.png"))); // NOI18N
        miAppConfig.setText("პროგრამის პარამეტრები");
        miAppConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAppConfigActionPerformed(evt);
            }
        });
        mnAdmin.add(miAppConfig);
        mnAdmin.add(jSeparator1);

        miStructure.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/application_cascade.png"))); // NOI18N
        miStructure.setText("კომპანიის სტრუქტურა");
        miStructure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miStructureActionPerformed(evt);
            }
        });
        mnAdmin.add(miStructure);

        miUserEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/user_edit.png"))); // NOI18N
        miUserEdit.setText("მომხმარებლთა მართვა");
        miUserEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miUserEditActionPerformed(evt);
            }
        });
        mnAdmin.add(miUserEdit);

        miUserGroups.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/group.png"))); // NOI18N
        miUserGroups.setText("მომხმ. ჯგუფების მართვა");
        miUserGroups.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miUserGroupsActionPerformed(evt);
            }
        });
        mnAdmin.add(miUserGroups);
        mnAdmin.add(jSeparator4);

        miFlowPermission.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ge/telasi/resorces/icons16x16/email_go.png"))); // NOI18N
        miFlowPermission.setText("მიმოსვლის კონფიგურაცია");
        miFlowPermission.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miFlowPermissionActionPerformed(evt);
            }
        });
        mnAdmin.add(miFlowPermission);

        jMenuBar1.add(mnAdmin);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents

    private void miExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExitActionPerformed
        System.exit(0);
}//GEN-LAST:event_miExitActionPerformed

    private void miAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAboutActionPerformed
        AboutDialog dialog = new AboutDialog(this);
        UIUtils.openDialog(dialog);
}//GEN-LAST:event_miAboutActionPerformed

    private void miStructureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miStructureActionPerformed
        if (validateConnection()) {
            StructureView view = new StructureView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
}//GEN-LAST:event_miStructureActionPerformed

    private void miRegistrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miRegistrationActionPerformed
        ServerItemSelectorDialog serverDialog = new ServerItemSelectorDialog(this);
        serverDialog.refresh();
        UIUtils.openDialog(serverDialog);
        if (serverDialog.getServerItem() != null) {
            Platform.getDefault().setServerItem(serverDialog.getServerItem());
            UserRegistrationDialog dialog = new UserRegistrationDialog(this);
            UIUtils.openDialog(dialog);
            if (dialog.isApproved()) {
                LocaleManager lm = Platform.getDefault().getLocaleManager();
                String firstName = dialog.getUser().getFirstName();
                String msg = lm.getMessage("MainFrame.registrationComplete", firstName);
                UIUtils.showMessage(this, msg);
            }
        }
}//GEN-LAST:event_miRegistrationActionPerformed

    private void miAppConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAppConfigActionPerformed
        if (validateConnection()) {
            AppConfigView view = new AppConfigView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
    }//GEN-LAST:event_miAppConfigActionPerformed

    private void miUserEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUserEditActionPerformed
        if (validateConnection()) {
            UserAdminView view = new UserAdminView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
    }//GEN-LAST:event_miUserEditActionPerformed

    private void miLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoginActionPerformed
        LoginDialog dialog = new LoginDialog(this);
        UIUtils.openDialog(dialog);
    }//GEN-LAST:event_miLoginActionPerformed

    private void miLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLogoutActionPerformed
        Platform pl = Platform.getDefault();
        if (pl.isConnected()) {
            LocaleManager lm = pl.getLocaleManager();
            String key = "MainFrame.confirmLogout";
            String msg = lm.getMessage(key, pl.getUser().getFullName());
            if (UIUtils.askConfirmation(this, msg)) {
                pl.disconnect();
                pl.resetOnConnectionChange();
            }
        }
    }//GEN-LAST:event_miLogoutActionPerformed

    private void miCnangePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCnangePasswordActionPerformed
        if (validateConnection()) {
            ChangePasswordDialog dialog = new ChangePasswordDialog(this);
            UIUtils.openDialog(dialog);
        }
    }//GEN-LAST:event_miCnangePasswordActionPerformed

    private void miMyAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMyAccountActionPerformed
        if (validateConnection()) {
            User user = Platform.getDefault().getUser();
            UserPropertiesDialog dialog = new UserPropertiesDialog(this);
            dialog.setUser(user);
            UIUtils.openDialog(dialog);
        }
    }//GEN-LAST:event_miMyAccountActionPerformed

    private void miUserGroupsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUserGroupsActionPerformed
        if (validateConnection()) {
            GroupAdminView view = new GroupAdminView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
}//GEN-LAST:event_miUserGroupsActionPerformed

    private void miTasksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miTasksActionPerformed
        if (validateConnection()) {
            if(taskFrame == null) {
                TaskView view = new TaskView();
                if (view.refresh()) {
                    openView(view, true);
                    taskFrame = view;
                    taskFrame.addInternalFrameListener(new InternalFrameAdapter() {
                        @Override
                        public void internalFrameClosed(InternalFrameEvent e) {
                            taskFrame = null;
                        }
                    });
                }
            } else {
                try {
                    taskFrame.moveToFront();
                    taskFrame.setIcon(false);
                    taskFrame.setSelected(true);
                    taskFrame.refresh();
                } catch (Exception ex) {}
            }
            Launcher.showNewMessageIcon = false;
            Launcher.validateTrayIcon();
        }
}//GEN-LAST:event_miTasksActionPerformed

    private void miFlowPermissionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miFlowPermissionActionPerformed
        if (validateConnection()) {
            FlowPermissionAdminView view = new FlowPermissionAdminView();
            openView(view, false);
        }
    }//GEN-LAST:event_miFlowPermissionActionPerformed

    private void miFlowPermissionViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miFlowPermissionViewActionPerformed
        if (validateConnection()) {
            FlowPermissionView view = new FlowPermissionView();
            openView(view, false);
        }
    }//GEN-LAST:event_miFlowPermissionViewActionPerformed

    private void miUserViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUserViewActionPerformed
        if (validateConnection()) {
            UserView view = new UserView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
    }//GEN-LAST:event_miUserViewActionPerformed

    private void miUserGroupViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUserGroupViewActionPerformed
        if (validateConnection()) {
            GroupView view = new GroupView();
            if (view.refresh()) {
                openView(view, false);
            }
        }
    }//GEN-LAST:event_miUserGroupViewActionPerformed

    private void miHomePageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miHomePageActionPerformed
        try {
            Desktop.getDesktop().browse(new URI("http://192.168.1.222/mediawiki/"));
        } catch (Exception ex) {
            LoggerUtils.manageException(this, ex);
        }
    }//GEN-LAST:event_miHomePageActionPerformed

    private void miNewTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewTaskActionPerformed
        if (validateConnection()) {
            NewTaskDialog dialog = new NewTaskDialog(this);
            UIUtils.openDialog(dialog);
        }
    }//GEN-LAST:event_miNewTaskActionPerformed

    private void miTaskCompilationReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miTaskCompilationReportActionPerformed
        if (validateConnection()) {
            TaskCompReportFrame report = new TaskCompReportFrame();
            openView(report, true);
        }
    }//GEN-LAST:event_miTaskCompilationReportActionPerformed

    protected void openView(JInternalFrame view, boolean maximize) {
        jDesktopPane1.add(view);
        if (!maximize) {
            view.setLocation(10, 10);
        } else {
            try {
                view.setMaximum(true);
            } catch (Exception ex) {}
        }
        view.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator0;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JMenuItem miAbout;
    private javax.swing.JMenuItem miAppConfig;
    private javax.swing.JMenuItem miCnangePassword;
    private javax.swing.JMenuItem miExit;
    private javax.swing.JMenuItem miFlowPermission;
    private javax.swing.JMenuItem miFlowPermissionView;
    private javax.swing.JMenuItem miHomePage;
    private javax.swing.JMenuItem miLogin;
    private javax.swing.JMenuItem miLogout;
    private javax.swing.JMenuItem miMyAccount;
    private javax.swing.JMenuItem miNewTask;
    private javax.swing.JMenuItem miRegistration;
    private javax.swing.JMenuItem miStructure;
    private javax.swing.JMenuItem miTaskCompilationReport;
    private javax.swing.JMenuItem miTasks;
    private javax.swing.JMenuItem miUserEdit;
    private javax.swing.JMenuItem miUserGroupView;
    private javax.swing.JMenuItem miUserGroups;
    private javax.swing.JMenuItem miUserView;
    private javax.swing.JMenu mnAdmin;
    private javax.swing.JMenu mnMain;
    private javax.swing.JMenu mnWebPage;
    // End of variables declaration//GEN-END:variables

    void resetTitle() {
        Platform pl = Platform.getDefault();
        LocaleManager lm = pl.getLocaleManager();
        if (pl.isConnected()) {
            setTitle(lm.getMessage("MainFrame.title1", pl.getUser().getFullName(),
                    pl.getServerItem().toString()));
            mnAdmin.setVisible(pl.getUser().isAdmin());
        } else {
            setTitle(lm.getMessage("MainFrame.title0"));
            mnAdmin.setVisible(false);
        }
    }

    boolean validateConnection() {
        Platform pl = Platform.getDefault();
        if (!pl.isConnected()) {
            if (pl.getServerManager().autoLogin()) return true;
            miLoginActionPerformed(null);
        }
        return pl.isConnected();
    }

}
